import random
import time
from selenium import webdriver
class Driver:
    driver = None
    @classmethod
    def get_driver(cls):
        if cls.driver is None:
            cls.driver = webdriver.Chrome()
            cls.driver.get("http://localhost/")
            time.sleep(1)
        return cls.driver
    @classmethod
    def quit_driver(cls):
        if cls.driver is not None:
            cls.driver.quit()
            cls.driver = None

def ass_text(ele):
    driver=Driver.get_driver()
    time.sleep(1)
    text=driver.find_element(*ele).text
    return text

import re
import sys
import time
from datetime import datetime
import allure
from pytest00.data import usercount, password, paramss_pass

class Data_way:
    def monk_data(self,n):
        a=random.randint(1, n)
        if n==3:
            a=2
        return a

cc=Data_way().monk_data(6)
print(cc)
def time_data():
    timd_id=time.time()
    time_norm =(str(datetime.now())).replace(":",".")
    return int(timd_id*1000),time_norm[:19:]

tt = time_data()[1]
pascount=0
failcount=0
def err(way,*can):#方法，方法参数
    wa=str(way)
    if 'function' in wa:
        w = re.findall("function(.*?)at", str(way))
    else:
        w = re.findall("'(.*?)'", wa)
    t = time_data()[1]
    try:
        result=way(*can)
        rt="%s-%s执行成功 \n"%(t,w)
        te_report(rt, tt)
    except Exception as e:
        global failcount
        failcount=failcount+1
        result="fail-%s-%s步骤异常,报错信息：%s\n"%(t,w,e)
        te_report(result, tt)
        sys.exit()
    return result


@allure.step(title='登录原始数据')
def login(count,pas):#登录，获取toast
    #a=0/0
    if count in usercount and pas in password:
        toast = "登录成功"
    elif count == ""or pas == "":
        toast = "请输入账号/密码22"
    else:
        toast = "账号/密码错误"
    return toast
@allure.step(title='新建原始数据')
def new_form(d1,d2,d3):
    #a = 0 / 0
    if  d1 in paramss_pass and  d2 in paramss_pass and  d3 in paramss_pass:
        toast="提交成功"
    else:
        toast="请输入"
    return toast


def te_report(text,n):
    f=open(r"D:\7z\te\report%s.txt"%n,"a")
    f.write(text)
    f.close()

def ass(res,result,*can):#断言，两个结果+执行参数
    global tt,pascount,failcount
    t = time_data()[1]
    if str(res) == str(result):
        pascount=pascount+1
        text = "case%d-pass-%s-执行参数：%s，执行结果：%s，预期结果：%s\n" % (pascount,t, str(can), res,result)
        te_report(text, tt)
    else:
        failcount=failcount+1
        text = "case%d-fail-断言失败-%s-执行参数：%s，实际结果：%s，预期结果：%s\n" % (failcount,t, str(can), res, result)
        te_report(text, tt)

def ass2(res,result,*can):#断言：前置条件错误，不统计用例数
    global tt,pascount,failcount
    t = time_data()[1]
    if res == result:
        text = "pass-%s-执行参数：%s，执行结果：%s，预期结果：%s\n" % (t, str(can), res,result)
        te_report(text, tt)
    else:
        text = "fail-断言失败-%s-执行参数：%s，实际结果：%s，预期结果：%s\n" % (t, str(can), res, result)
        te_report(text, tt)

def sum1():
    global tt, pascount, failcount
    text = "总执行%d个，成功%d个，失败%d个\n" % (pascount + failcount, pascount, failcount)
    te_report(text, tt)





























